<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/page/common/commonPage.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加菜单</title>
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/smartadmin-production.min.css">
</head>
<body>
    <%@ include file="/WEB-INF/page/common/header.jsp"%>
    <%@ include file="/WEB-INF/page/common/leftSideBar.jsp"%>

    <div id="main" role="main">
        <div id="ribbon">
            <ol class="breadcrumb">
                <li>首页</li>
                <li>菜单管理</li>
                <li>添加菜单</li>
            </ol>
        </div>
        <div id="content">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <div class="jarviswidget">
                        <header>
                            <h2><i class="fa fa-plus"></i> 添加菜单</h2>
                        </header>
                        <div class="widget-body">
                            <form id="addForm" class="smart-form">
                                <fieldset>
                                    <section>
                                        <label class="label">菜单名称</label>
                                        <label class="input">
                                            <i class="icon-append fa fa-font"></i>
                                            <input type="text" name="menuName" class="form-control" required>
                                        </label>
                                    </section>
                                    
                                    <section>
                                        <label class="label">英文名称</label>
                                        <label class="input">
                                            <i class="icon-append fa fa-font"></i>
                                            <input type="text" name="menuNameUs" class="form-control" required>
                                        </label>
                                    </section>
                                    
                                    <section>
                                        <label class="label">父级菜单</label>
                                        <label class="select">
                                            <select name="parentId" class="form-control">
                                                <option value="">无(作为一级菜单)</option>
                                                <c:forEach items="${parentMenus}" var="parent">
                                                    <option value="${parent.menuId}">${parent.menuName}</option>
                                                </c:forEach>
                                            </select>
                                            <i></i>
                                        </label>
                                    </section>
                                    
                                    <section>
                                        <label class="label">链接类型</label>
                                        <label class="select">
                                            <select name="linkType" class="form-control" required>
                                                <option value="N">无链接</option>
                                                <option value="H">首页</option>
                                                <option value="L">列表</option>
                                                <option value="P">页面</option>
                                                <option value="C">自定义</option>
                                            </select>
                                            <i></i>
                                        </label>
                                    </section>
                                    
                                    <section>
                                        <label class="label">打开方式</label>
                                        <label class="select">
                                            <select name="openType" class="form-control" required>
                                                <option value="0">原窗口</option>
                                                <option value="1">新窗口</option>
                                            </select>
                                            <i></i>
                                        </label>
                                    </section>
                                    
                                    <section>
                                        <label class="label">链接地址</label>
                                        <label class="input">
                                            <i class="icon-append fa fa-link"></i>
                                            <input type="text" name="link" class="form-control">
                                        </label>
                                    </section>
                                    
                                    <section>
                                        <label class="label">显示顺序</label>
                                        <label class="input">
                                            <i class="icon-append fa fa-sort-numeric-asc"></i>
                                            <input type="number" name="seq" class="form-control" required>
                                        </label>
                                    </section>
                                </fieldset>
                                
                                <footer>
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fa fa-save"></i> 保存
                                    </button>
                                    <button type="button" class="btn btn-default" onclick="window.location.href='${base}/backmenu/list'">
                                        <i class="fa fa-times"></i> 取消
                                    </button>
                                </footer>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="${resourcesUrl}/common/js/jquery-1.8.2.min.js"></script>
    <script src="${resourcesUrl}/common/js/bootstrap/bootstrap.min.js"></script>
    <script src="${resourcesUrl}/common/js/plugin/jquery-validate/jquery.validate.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#addForm").validate({
                submitHandler: function(form) {
                    $.ajax({
                        url: '${base}/backmenu/save',
                        type: 'POST',
                        data: $(form).serialize(),
                        success: function(data) {
                            if(data.RET_CODE === 'success') {
                                alert('添加成功');
                                window.location.href = '${base}/backmenu/list';
                            } else {
                                alert(data.RET_MSG || '添加失败');
                            }
                        }
                    });
                    return false;
                }
            });
        });
    </script>
</body>
</html> 